using UnityEngine;

// 示例：玩家数据Model
public class PlayerModel : Model
{
    private string _name = "";
    private int _level = 1;
    private int _experience = 0;
    private float _health = 100f;
    
    // 玩家名称属性
    public string Name
    {
        get => _name;
        set => SetProperty(ref _name, value, nameof(Name));
    }
    
    // 等级属性
    public int Level
    {
        get => _level;
        set => SetProperty(ref _level, value, nameof(Level));
    }
    
    // 经验值属性
    public int Experience
    {
        get => _experience;
        set => SetProperty(ref _experience, value, nameof(Experience));
    }
    
    // 生命值属性
    public float Health
    {
        get => _health;
        set => SetProperty(ref _health, value, nameof(Health));
    }
    
    // 获取经验值百分比
    public float ExperiencePercentage => (float)_experience / GetRequiredExperience(_level);
    
    // 计算升级所需经验
    private int GetRequiredExperience(int level)
    {
        return level * 100; // 简单公式：每级需要等级*100经验
    }
    
    // 增加经验值
    public void AddExperience(int exp)
    {
        Experience += exp;
        
        // 检查是否可以升级
        while (Experience >= GetRequiredExperience(Level))
        {
            Experience -= GetRequiredExperience(Level);
            Level++;
            Debug.Log($"玩家升级了！当前等级：{Level}");
        }
    }
    
    // 受到伤害
    public void TakeDamage(float damage)
    {
        Health = Mathf.Max(0, Health - damage);
        if (Health <= 0)
        {
            Debug.Log("玩家死亡！");
        }
    }
    
    // 治疗
    public void Heal(float amount)
    {
        Health = Mathf.Min(100f, Health + amount);
    }
}

// 示例：游戏设置Model
public class GameSettingsModel : Model
{
    private float _musicVolume = 0.5f;
    private float _soundVolume = 0.7f;
    private bool _fullscreen = false;
    private int _qualityLevel = 2;
    
    // 音乐音量
    public float MusicVolume
    {
        get => _musicVolume;
        set => SetProperty(ref _musicVolume, Mathf.Clamp01(value), nameof(MusicVolume));
    }
    
    // 音效音量
    public float SoundVolume
    {
        get => _soundVolume;
        set => SetProperty(ref _soundVolume, Mathf.Clamp01(value), nameof(SoundVolume));
    }
    
    // 全屏设置
    public bool Fullscreen
    {
        get => _fullscreen;
        set => SetProperty(ref _fullscreen, value, nameof(Fullscreen));
    }
    
    // 画质等级
    public int QualityLevel
    {
        get => _qualityLevel;
        set => SetProperty(ref _qualityLevel, Mathf.Clamp(value, 0, 5), nameof(QualityLevel));
    }
} 